<template>
  <div class="complaint-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>投诉列表</span>
      </div>

      <el-table
        v-loading="loading"
        :data="complaintList"
        style="width: 100%"
        border
      >
        <el-table-column
          prop="id"
          label="ID"
          width="80"
        />
        <el-table-column
          prop="type"
          label="投诉类型"
          width="200"
        >
          <template slot-scope="scope">
            <span>{{ getTypeText(scope.row.type) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="content"
          label="投诉内容"
          min-width="200"
          show-overflow-tooltip
        />
        <el-table-column
          prop="image"
          label="投诉图片"
          width="150"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.image" class="image-list">
              <el-image
                v-for="(img, index) in getImageList(scope.row.image)"
                :key="index"
                :src="img"
                :preview-src-list="getImageList(scope.row.image)"
                fit="cover"
                style="width: 60px; height: 60px; margin-right: 5px; cursor: pointer;"
              />
            </div>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="ip"
          label="IP地址"
          width="140"
        />
        <el-table-column
          prop="create_time"
          label="创建时间"
          width="180"
        />
      </el-table>

      <div class="pagination-container">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import { getComplaintList } from '@/api/log'

export default {
  name: 'ComplaintList',
  data() {
    return {
      complaintList: [],
      loading: false,
      currentPage: 1,
      pageSize: 10,
      total: 0
    }
  },
  created() {
    this.getComplaintList()
  },
  methods: {
    // 获取投诉列表数据
    getComplaintList() {
      this.loading = true
      getComplaintList({
        page: this.currentPage.toString(),
        page_size: this.pageSize.toString()
      }).then(res => {
        this.complaintList = res.data.data || res.data.list || []
        this.total = res.data.total || 0
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 处理图片列表
    getImageList(imageStr) {
      if (!imageStr) return []
      return imageStr.split(',').map(img => img.trim()).filter(img => img)
    },
    // 获取投诉类型文本
    getTypeText(type) {
      const typeMap = {
        1: '包含欺诈信息(如:假红包)',
        2: '包含色情信息',
        3: '包含暴力恐怖信息',
        4: '包含政治敏感信息',
        5: '可能赌博信息',
        6: '其他'
      }
      return typeMap[type] || '未知类型'
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getComplaintList()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getComplaintList()
    }
  }
}
</script>

<style scoped>
.complaint-container {
  padding: 20px;
}
.pagination-container {
  margin-top: 20px;
  text-align: right;
}
.image-list {
  display: flex;
  flex-wrap: wrap;
}
</style>

